home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
archiver
/
unarj_s1.lzh
/
SOURCE.ST
/
UNARJ.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-10-05
|
25KB
|
1,060 lines
/* UNARJ.C, UNARJ, R JUNG, 10/05/92
* Main Extractor routine
* Copyright (c) 1991 by Robert K Jung. All rights reserved.
*
* This code may be freely used in programs that are NOT ARJ archivers
* (both compress and extract ARJ archives).
*
* If you wish to distribute a modified version of this program, you
* MUST indicate that it is a modified version both in the program and
* source code.
*
* If you modify this program, I would appreciate a copy of the new
* source code. I am holding the copyright on the source code, so
* please do not delete my name from the program files or from the
* documentation.
*
* I wish to give credit to Haruhiko Okumura for providing the
* basic ideas for ARJ and UNARJ in his program AR. Please note
* that UNARJ is significantly different from AR from an archive
* structural point of view.
*
* Modification history:
* Date Programmer Description of modification.
* 04/05/91 R. Jung Rewrote code.
* 04/23/91 M. Adler Portabilized.
* 04/29/91 R. Jung Added l command. Removed 16 bit dependency in
* fillbuf().
* 05/19/91 R. Jung Fixed extended header skipping code.
* 05/25/91 R. Jung Improved find_header().
* 06/03/91 R. Jung Changed arguments in get_mode_str() and
* set_ftime_mode().
* 06/19/81 R. Jung Added two more %c in printf() in list_arc().
* 07/07/91 R. Jung Added default_case_path() to extract().
* Added strlower().
* 07/20/91 R. Jung Changed uint ratio() to static uint ratio().
* 07/21/91 R. Jung Added #ifdef VMS.
* 08/28/91 R. Jung Changed M_DIFFHOST message.
* 08/31/91 R. Jung Added changes to support MAC THINK_C compiler
* per Eric Larson.
* 10/07/91 R. Jung Added missing ; to THINK_C additions.
* 11/11/91 R. Jung Added host_os test to fwrite_txt_crc().
* 11/24/91 R. Jung Added more error_count processing.
* 12/03/91 R. Jung Added backup file processing.
* 10/05/92 G. Zahn ST-Implementation
*
*/
#include "unarj.h"
#include <tos.h>
#ifdef MODERN
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#else /* !MODERN */
extern void free();
extern void exit();
extern char *strcat();
extern char *strcpy();
extern char *strncpy();
extern char *strchr();
extern char *strrchr();
extern int strlen();
extern int strcmp();
#ifdef VMS
#include <ssdef.h>
#define EXIT_FAILURE SS$_ABORT
#define EXIT_SUCCESS SS$_NORMAL
#else
#define EXIT_FAILURE (1)
#define EXIT_SUCCESS (0)
#endif
#define toupper(c) ((c)>='a'&&(c)<='z'?(c)-('a'-'A'):(c))
#define tolower(c) ((c)>='A'&&(c)<='Z'?(c)+('a'-'A'):(c))
#endif /* ?MODERN */
#ifdef THINK_C
#include <console.h>
#endif
/* Global variables */
UCRC crc;
FILE *arcfile;
FILE *outfile;
ushort bitbuf;
long compsize;
long origsize;
uchar subbitbuf;
uchar header[HEADERSIZE_MAX];
char arc_name[FNAME_MAX];
int command;
int bitcount;
int file_type;
int no_output;
int error_count;
/* Messages */
static char *M_USAGE [] =
{
" Usage:\n",
"UNARJ [v] archive[.arj] (list archive with pathnames)\n",
"UNARJ l archive[.arj] (list archive with statistics)\n",
"\n",
"UNARJ e archive[.arj] (extract archive)\n",
"UNARJ x archive[.arj] (extract with pathnames)\n",
"UNARJ t archive[.arj] (test archive)\n",
"\n",
"This is an UNARJ program for ATARI ST/STE/TT-computers by Gero Zahn.\n",
"You may freely use, copy and distribute this program, provided that no fee\n",
"is charged for such use, copying or distribution, and it is distributed\n",
"ONLY in its original unmodified state. UNARJ is provided as is without\n",
"warranty of any kind, express or implied, including but not limited to\n",
"the implied warranties of merchantability and fitness for a particular\n",
"purpose. Refer to the manual for more information.\n",
"\n",
" UNARJ for PC: Robert K Jung, Internet: robjung@world.std.com\n",
"ATARI-version: Gero Zahn, Internet: q92127@pbhrzx.uni-paderborn.de\n",
NULL
};
char M_VERSION [] = "UNARJ (ATARI-version) 2.30GZ (C)opyright 1991 Robert K Jung / 1992 Gero Zahn\n\n";
char M_ARCDATE [] = "Archive date : %s\n";
char M_BADCOMND[] = "Bad UNARJ command: %s";
char M_BADCOMNT[] = "Invalid comment header";
char M_BADHEADR[] = "Bad header";
char M_BADTABLE[] = "Bad Huffman code";
char M_CANTOPEN[] = "Can't open %s";
char M_CANTREAD[] = "Can't read file or unexpected end of file";
char M_CANTWRIT[] = "Can't write file. Disk full?";
char M_CRCERROR[] = "CRC error!\n";
char M_CRCOK [] = "CRC OK\n";
char M_DIFFHOST[] = " Binary file!";
char M_ENCRYPT [] = "File is password encrypted, ";
char M_ERRORCNT[] = "%sFound %5d error(s)!";
char M_EXTRACT [] = "Extracting %-25s";
char M_FEXISTS [] = "%-25s exists, ";
char M_HEADRCRC[] = "Header CRC error!";
char M_NBRFILES[] = "%5d file(s)\n";
char M_NOMEMORY[] = "Out of memory";
char M_NOTARJ [] = "%s is not an ARJ archive";
char M_PROCARC [] = "Processing archive: %s\n";
char M_SKIPPED [] = "Skipped %s\n";
char M_SUFFIX [] = ARJ_SUFFIX;
char M_TESTING [] = "Testing %-25s";
char M_UNKNMETH[] = "Unsupported method: %d, ";
char M_UNKNTYPE[] = "Unsupported file type: %d, ";
char M_UNKNVERS[] = "Unsupported version: %d, ";
#define get_crc() get_longword()
#define fget_crc(f) fget_longword(f)
#define setup_get(PTR) (get_ptr = (PTR))
#define get_byte() ((uchar)(*get_ptr++ & 0xff))
#define BUFFERSIZE 4096
#define ASCII_MASK 0x7F
#define CRCPOLY 0xEDB88320L
#define UPDATE_CRC(r,c) r=crctable[((uchar)(r)^(uchar)(c))&0xff]^(r>>CHAR_BIT)
/* Local functions */
#ifdef MODERN
static void make_crctable(void);
static void crc_buf(char *str, int len);
static void strparity(uchar *p);
static FILE *fopen_msg(char *name, char *mode);
static int fget_byte(FILE *f);
static uint fget_word(FILE *f);
static ulong fget_longword(FILE *f);
static void fread_crc(uchar *p, int n, FILE *f);
static void decode_path(char *name);
static void get_date_str(char *str, ulong tstamp);
static int parse_path(char *pathname, char *path, char *entry);
static void strncopy(char *to, char *from, int len);
static uint get_word(void);
static ulong get_longword(void);
static long find_header(FILE *fd);
static int read_header(int first, FILE *fd, char *name);
static void skip(void);
static void unstore(void);
static int check_flags(void);
static int extract(void);
static int test(void);
static uint ratio(long a, long b);
static void list_start(void);
static void list_arc(int count);
static void verb_start(void);
static void verb_arc(int count);
static void execute_cmd(void);
static void help(void);
#endif /* MODERN */
/* Local variables */
static char filename[FNAME_MAX];
static char comment[COMMENT_MAX];
static char *hdr_filename;
static char *hdr_comment;
static ushort headersize;
static uchar first_hdr_size;
static uchar arj_nbr;
static uchar arj_x_nbr;
static uchar host_os;
static uchar arj_flags;
static short method;
static uint file_mode;
static ulong time_stamp;
static short entry_pos;
static ushort host_data;
static uchar *get_ptr;
static UCRC file_crc;
static UCRC header_crc;
static long first_hdr_pos;
static long torigsize;
static long tcompsize;
static int clock_inx;
static char *writemode[2] = { "wb", "w" };
static UCRC crctable[UCHAR_MAX + 1];
/* Functions */
static void
make_crctable()
{
uint i, j;
UCRC r;
for (i = 0; i <= UCHAR_MAX; i++)
{
r = i;
for (j = CHAR_BIT; j > 0; j--)
{
if (r & 1)
r = (r >> 1) ^ CRCPOLY;
else
r >>= 1;
}
crctable[i] = r;
}
}
static void
crc_buf(str, len)
char *str;
int len;
{
while (len--)
UPDATE_CRC(crc, *str++);
}
void
disp_clock()
{
static char cloc